﻿using System.Web.Mvc;
using NHibernate.Tool.hbm2ddl;
using Hippo.Core;
using Evolus.Mercury.Model;

namespace Evolus.Mercury.Web.Controllers
{
    public class SetupController : Controller
    {
        IMarketService marketService;

        public SetupController(IMarketService marketService)
        {
            this.marketService = marketService;
        }

        public ActionResult Index()
        {
            string name = "main.cfg";
            SchemaExport schemaExport = new SchemaExport(ServiceFactory.Get<NHibernate.Cfg.Configuration>(name));
            schemaExport.Create(true, true);

            GenerateRequiredData();

            return View();
        }

        private void GenerateRequiredData()
        {
            Market market = new Market();
            market.Name = "Ho Chi Minh City Stock Exchange";
            market.Code = "HoSE";
            market.IndexName = "VN-Index";
            marketService.AddMarket(market);

            market = new Market();
            market.Name = "Hanoi Stock Exchange";
            market.Code = "HaSTC";
            market.IndexName = "HaSTC-Index";
            marketService.AddMarket(market);
        }
    }
}
